package com.example.springbootdyapi.controller;

//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

//@Api(tags="天气查询接口")
@RestController
@RequestMapping("weather")
public class WeatherController {
    @Autowired
    RestTemplate restTemplate;

    //    @ApiOperation(value = "天气查询接口",notes = "返回最近7天天气预报")
    @GetMapping
    public String weather(String ip) {
        //String apiURL = "http://aider.meizu.com/app/weather/listWeather?cityIds=110100";
        String apiURL = "http(s)://jisutqybmf.market.alicloudapi.com/weather/query?ip="+ip;
        ResponseEntity<String> forEntity = restTemplate.getForEntity(apiURL, String.class);

        if (200 == forEntity.getStatusCodeValue()) {
            return forEntity.getBody();
        } else {
            return "error with code:" + forEntity.getStatusCodeValue();
        }

    }





}